<?php
/**
 * YouNet
 *
 * @category   Application_Extensions
 * @package    Adv Menu system
 * @copyright  Copyright 2011 YouNet Company
 * @license    http://www.modules2buy.com/
 * @version    $Id: AdminSettingsController.php
 * @author     Minh Nguyen
 */
class Advmenusystem_AdminStylesController extends Core_Controller_Action_Admin
{
  public function init()
  {
    $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')
      ->getNavigation('advmenusystem_admin_main', array(), 'advmenusystem_admin_main_styles');
  }
  public function indexAction()
  {
    $this->view->form = $form = new Advmenusystem_Form_Admin_Style();
	$values = Engine_Api::_()->getApi('settings', 'core')->getSetting('avdmenusystem.customcssobj', 0);
	$values = Zend_JSON::decode($values);
	if($values)
		$form->populate($values);
   if( $this->getRequest()->isPost() && $form->isValid($this->_getAllParams()) )
    {
	     $values = $form->getValues();
	     $str = $this->view->partial("_css.tpl");
		 $arr_keys = array_keys($values);
		 $arr_values = array_values($values);
		 $arr_keys = array_map(array($this ,'map'), $arr_keys);
		 $str = str_replace($arr_keys, $arr_values, $str);
		 Engine_Api::_()->getApi('settings', 'core')->setSetting('avdmenusystem.customcssobj', Zend_JSON::encode($values));
		 Engine_Api::_()->getApi('settings', 'core')->setSetting('avdmenusystem_customcss', $str);
	     $form->addNotice('Your changes have been saved.');
    }
  }
  static public function map($a)
  {
  		return "[{$a}]";
  }
}
